package com.ruoyi.front;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableSupport;
import com.ruoyi.common.utils.UnzipAndListFilesUtils;
import com.ruoyi.system.domain.SysDoc;
import com.ruoyi.system.service.ISysDocService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

//搜索
@Controller
public class search extends footcontroller {
    @Autowired
    private ISysDocService iSysDocService;
    @GetMapping({"/search.htm"})
    public String search(ModelMap modelMap, @RequestParam("key") String key, @RequestParam(value = "exten",defaultValue = "") String exten)
    {
        //String  where1 = "";
        /*if(!key.isEmpty()) {
            String[] keyarr = UnzipAndListFilesUtils.fenci(key).split(",");
            for (int i=0;i<keyarr.length;i++)
            {
                where1 += "SIGN(LOCATE('"+keyarr[i]+"',d.title)) + ";
            }
        }
        int endIndex =  where1.length() - 3; // 计算倒数第三个字符的索引
        if(endIndex>0)
            where1 = where1.substring(0,endIndex);

         */
        List<SysDoc> sysDocList = iSysDocService.searchSysDocListBykeyexten(key,exten);
        startPage();
        modelMap.put("key",key);
        modelMap.put("exten",exten);
        modelMap.put("docs",sysDocList);
        modelMap.put("pagesize",10);
        modelMap.put("cpage", TableSupport.buildPageRequest().getPageNum());
        modelMap.put("total",sysDocList.size());
        getabout(modelMap);
        return "doc/search";
    }
}
